class Solution {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        k %= n;
        reserve(nums,0,n - k);
        reserve(nums,n - k,n);
        reserve(nums,0,n);
    }
    public static void reserve(int[] arr,int left,int right){
        while(left < right - 1){
            int mid = arr[left];
            arr[left] = arr[right - 1];
            arr[right - 1 ] = mid;
            left++;
            right--;
        }
    }
}